<template>
  <div>
    <el-dialog
      title="查看"
      :visible.sync="dialogVisible"
      width="80%"
    >
      <el-row>
        <el-col :span="24">
          <el-form
            :model="dataForm"
            label-width="120px"
            label-position="right"
            :rules="dataRule"
          >
            <div class="rwfqnew">
              <el-row>
                <el-col :span="24">
                  <el-col :span="12">
                    <el-form-item label="模板名称" prop="mbname">
                      <el-input
                        disabled
                        v-model="dataForm.mbname"
                        placeholder="模板名称"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="描述" prop="description">
                      <el-input
                        disabled
                        v-model="dataForm.description"
                        placeholder="描述"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                </el-col>
              </el-row>
            </div>
          </el-form>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="24">
          <el-table
            style="width: 100%; margin-top: 20px"
            :data="dataList"
            border
            ref="table"
            v-loading="loading"
          >
            <el-table-column type="selection" width="55"> </el-table-column>
            <el-table-column
              type="index"
              width="80"
              header-align="center"
              align="center"
              label="序号"
            ></el-table-column>
            <el-table-column
              prop="pfxm"
              width="350"
              header-align="center"
              align="center"
              label="评分项目"
            >
              <template slot-scope="scope">
                <el-input
                  v-if="!disabled"
                  @change="
                    changeValue(scope.row.pfxm, 'pfxm', scope.row.id)
                  "
                  v-model="scope.row.pfxm"
                  placeholder="评分项目"
                />
                <span v-else>{{ scope.row.pfxm }}</span>
              </template>
            </el-table-column>
            <el-table-column
              prop="fssz"
              width="352"
              header-align="center"
              align="center"
              label="分数设置"
            >
              <template slot-scope="scope">
                <el-input
                  v-if="!disabled"
                  @change="
                    changeValue(scope.row.fssz, 'fssz', scope.row.id)
                  "
                  v-model="scope.row.fssz"
                  placeholder="分数设置"
                />
                <span v-else>{{ scope.row.fssz }}</span>
              </template>
            </el-table-column>
            <el-table-column
              prop="pfsm"
              width="350"
              header-align="center"
              align="center"
              label="评分说明"
            >
              <template slot-scope="scope">
                <el-input
                  v-if="!disabled"
                  @change="
                    changeValue(scope.row.pfsm, 'pfsm', scope.row.id)
                  "
                  v-model="scope.row.pfsm"
                  placeholder="评分说明"
                />
                <span v-else>{{ scope.row.pfsm }}</span>
              </template>
            </el-table-column>


          </el-table>
        </el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" plain @click="backBtn">关闭</el-button>
      </span>
    </el-dialog>

  </div>
</template>

<script>

import {
  removeDetailById,
  updateDetailById,
  addDetail,
  rejected,
  updateForFaqi
} from "@/api/hetongrenwu/zhongdian/renwuchuangjian";
import { getzxgzZibiaoPage } from "@/api/hetongrenwu/zhuanxianggongzuo/zxgzmbcj";
import { effective } from "@/api/hetongrenwu/hetongyeji/hetongnd";
export default {
  components: {

  },
  props: {},
  data() {

    return {
      dataForm: {},
      shouyuerendataList: [],
      categoryList: [],

      dataList: [],
      zdrwBkhUsers: [],
      dialogVisible: false,
      index: 1,
      state: Number,
      loading: false,
      loadingrejected: false,
      disabled: Boolean,
      dataRule: {
          mbname: [
              { required: true, message: "请输入模板名称", trigger: "change" },
          ],
          description: [
              { required: true, message: "请输入描述", trigger: "change" },
          ]
      },
    };
  },
  watch: {},
  created() {
    this.fneffective();
  },
  methods: {
    init(row) {
      this.dataForm = row;

      this.dialogVisible = true;
      this.fngetDetailListdepid(row.id);
      // 0 (创建中)   4(考核人驳回)   6(汇总驳回)
      if (row.state == 0 || row.state == 4 || row.state == 6) {
        this.disabled = false;
      } else {
        this.disabled = true;
      }
    },
    backBtn() {
      this.dialogVisible = false;
      this.$emit("fnBackLastPage", "返回原页面");
    },
    changeValue(val, type, id) {
      console.log(val, type, id);
      var params = {
        [type]: val,
        id: id,
      };
      updateDetailById(params).then((res) => {
        this.$message.closeAll();
        this.$message.success("修改成功");
        this.fngetDetailListdepid(this.dataForm.id);
      });
    },
    changeHead(val, type, id){
      var param ={
        [type]: val,
        id: id,
      }
      updateForFaqi(param).then((res) => {
        this.$message.closeAll();
        this.$message.success("修改成功");
        this.fngetDetailListdepid(this.dataForm.id);
      });
    },
    fneffective() {
      effective({
        tagName: "重点任务",
      }).then((res) => {
        this.categoryList = res.data.data;
      });
    },
    fngetDetailListdepid(pfmbid) {
      this.loading = true;

        getzxgzZibiaoPage({ pfmbid }).then((response) => {
        this.dataList = response.data.data;
        console.log(this.dataList);
        this.loading = false;
      });
    },
    rejectedBtn() {
      var data = this.$refs.table.selection;
      this.loadingrejected = true;
      rejected({ rows: data }).then((res) => {
        this.$message.success("驳回成功");
        this.loadingrejected = false;
        this.fngetDetailListdepid(this.dataForm.id);
      });
    },
    submitfy(data) {
      this.zdrwBkhUsers = [];
      this.shouyuerendataList = [];
      this.shouyuerendataList = data.tableDataUser;
      console.log(JSON.stringify(this.shouyuerendataList));
      var obj = {};
      this.shouyuerendataList.forEach((ele) => {
        var user = {};
        user.userId = ele.userId;
        user.userName = ele.userCode;
        user.ryName = ele.userName;
        user.deptId = ele.deptId;
        user.userDeptName = ele.deptName;
        user.userZw = ele.userZw;
        user.userLx = "总部发起";
        user.userZj = ele.userZj;
        this.zdrwBkhUsers.push(user);
      });
    },
    delBtn(row) {
      removeDetailById(row.id).then((res) => {
        this.$message.closeAll();
        this.$message.success("删除成功");
        this.fngetDetailListdepid(this.dataForm.id);
      });
    },
    addBtn() {
      var str = this.getNowTime();
      var str2 = this.getNowTime2();
      console.log(str);
      var item = {
        renwuName: "任务名称" + this.index + 1,
        bkhName: "1",
        zycd: "较高",
        wcnd: "较高",
        weightset: "0",
        rwYxqq: str,
        rwYxqz: str2,
        workTarget: "无",
        dataProvider: "1",
        providerName: "1",
        index: this.index,
        ndId: this.dataForm.id,
        renwuId: this.dataForm.renwuId,
      };
      this.index++;
      var setData = ""
      setData = new Date(this.dataForm.signDate).getTime();
      var now = new Date();
      var year = now.getFullYear(); //得到年份
      var month = now.getMonth()+1;//得到月份
      var date = now.getDate();//得到日期
      if (month < 10) month = "0" + month;
      if (date < 10) date = "0" + date;
      var nowdate = year + "-" + month + "-" + date;
      if(setData>=new Date(nowdate).getTime()){
        item.renwuType = ""
      }else{
        item.renwuType = "追加"
      }
      addDetail(item).then((res) => {
        this.$message.success("添加成功");
        this.fngetDetailListdepid(this.dataForm.id);
      });
    },
    getNowTime: function () {
      let dateTime;
      let yy = new Date().getFullYear();
      let mm = new Date().getMonth() + 1;
      let dd = new Date().getDate();
      dateTime = yy + "-" + mm + "-" + dd;
      return dateTime;
    },
    getNowTime2: function () {
      let dateTime;
      let yy = new Date().getFullYear();
      let mm = new Date().getMonth() + 2;
      let dd = new Date().getDate();
      dateTime = yy + "-" + mm + "-" + dd;
      return dateTime;
    },
  },
};
</script>

<style scoped>
.rwfqnew {
  border-radius: 16px;
  -webkit-box-shadow: 5px 5px 10px #e3e3ea, -5px -5px 10px #ffffff;
  box-shadow: 5px 5px 10px #e3e3ea, -5px -5px 10px #ffffff;
  background: #fbfbfd;
  padding: 10px 30px 30px 30px;
}
</style>
